package com.mutouren.common.session.impl;

import javax.servlet.http.HttpServletRequest;

import com.mutouren.common.session.Session;
import com.mutouren.common.session.UserInfo;

public class ServletSessionImpl implements Session {
	
	private final static String keyName = "userInfo";

	@Override
	public UserInfo get(HttpServletRequest request) {
		return (UserInfo)request.getSession().getAttribute(keyName);
	}

	@Override
	public void set(HttpServletRequest request, String sessionId, UserInfo userInfo) {
		request.getSession().setAttribute(keyName, userInfo);
	}

	@Override
	public void delete(HttpServletRequest request) {
		request.getSession().removeAttribute(keyName);
		request.getSession().invalidate();
	}

}
